<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
</head>
<body>
<?php

/**
* php类知识点练习
*/
class ShopProduct {

    private $cost = 100;
    public $name = '宝贝';
    public $price = 120;
    protected $sell   = 1;
    
    // 定义构造方法，构造方法通常用来进行对象的初始化工作。
    public function __construct($name = '',$price = 0,$cost = 0,$sell = 0)
    {
        $this->name = $name;
        $this->price = $price;
        $this->cost = $cost;
        $this->sell = $sell;
    }

    // 定义类的方法
    public function display()
    {
        return $this->name . '的价格是：' . $this->price;
    }


}

// 定义书籍类

/**
* 书籍类
*/
class Book extends ShopProduct
{
    public $author = '';
    public $version = 1;
    public $press = '';

    function __construct($name = '',$price = 0,$cost = 0,$sell = 0,$author='',$version = 0,$press='')
    {
        parent::__construct($name,$price,$cost,$sell);
        $this->author = $author;
        $this->version = $version;
        $this->press = $press;
    }
}

// 对象的生成

$p1 = new ShopProduct();
$p2 = new ShopProduct('小米6',2999,2000,2000);

$p3 = new Book('PHP核心语法',29.99,2.9,100,'John',1,'机械工业出版社');
// 访问类的属性

// 使用类的方法
echo '<pre>';
echo $p3->display();
// var_dump($p1->name);
// var_dump($p1->sell);
echo '</pre>';

?>
</body>
</html>
